package com.ymatou.iapi.app.keyword.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;




import com.ymatou.iapi.app.keyword.parameter.ProductKeywordBean;
import com.ymatou.iapi.app.keyword.service.ProductKeywordCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.database.sqlwapper.AppDefaultWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;

/**
*查找好货商品接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ProductKeyword{
	private static ProductKeywordBean searchproductinappBean;
	private static ProductKeywordCall searchproductinappCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("app好货商品接口");
	}

	@Before
	public void caseUp() {
		searchproductinappBean=new ProductKeywordBean();
		searchproductinappCall=new ProductKeywordCall();
		
	}

	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(searchproductinappCall.getOpurl());
		//Logger.generateResult();
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_ProductKeyword_001() {
		Logger.start(true,"app好货商品接口- 比较接口返回记录数与数据库查找返回是否一致");
		
		try {
			//设置参数
			String text= "测试";
			String textUsql = "keyword(mixkeyword,"+text+")";
			
			searchproductinappBean.setQuery(textUsql);
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();
			
			//从数据库获取商品数量
			List<Map> list=new DefaultWapper().selectProductInPc(text);
			List<Map> list2 = new AppDefaultWapper().selectProductInApp(text);
			
			//将M端和C端数据相加
			int returnNum =(Integer) list.get(0).get("num")+ (Integer) list2.get(0).get("num");
			
			Logger.verifyEquals(returnNum, searchproductinappCall.getTotal(),"app中查找好货商品接口返回记录数是否正确");
			Logger.verifyEquals("OK",searchproductinappCall.getStatus() , "接口调用成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_002() {
		Logger.start(true,"app好货商品接口- 验证接口返回的公共数据");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue,sort:apphaohuo1");
			searchproductinappBean.setFl("sproductid,source");
			searchproductinappBean.setLimit("0,10");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			Logger.verifyEquals("OK",searchproductinappCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(requestid,searchproductinappCall.getCommonInfo("requestid") , "检查接口请求id值");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("hostip"), "验证hostip不为空");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("algorithm"), "验证algorithm不为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_003() {
		Logger.start(true,"app好货商品接口- 按关键字搜索，校验返回数据是否匹配关键字");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue,sort:apphaohuo1");
			searchproductinappBean.setFl("sproductid,source,mixkeyword");
			searchproductinappBean.setLimit("0,10");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			JSONArray hits = searchproductinappCall.getHits();

			// 获取接口返回数据中的所有sproduct值
			for (int i = 1; i <= hits.length(); i++) {
				String hitsOne = hits.getString(i - 1);
				JSONObject hitsOnes = new JSONObject(hitsOne);
				String name = (String) hitsOnes.get("mixkeyword");

				Logger.verifyIsContains(keyword, name, "第" + i+ "条记录中mixkeyword=" + keyword + "的直播匹配结果");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_004() {
		Logger.start(true,"app好货商品接口- 验证返回结果中前100条记录是否存在重复");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue,sort:apphaohuo1");
			searchproductinappBean.setFl("sproductid,source");
			searchproductinappBean.setLimit("0,100");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			JSONArray hitsAry = searchproductinappCall.getHits();
			
			List<String> list = new ArrayList<String>();

			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				
				String id = json.getString("sproductid");
				
				if (list.contains(id) == true) {

					Logger.verifyEquals(false, list.contains(id), "验证第" + i+ "条返回数据的id存在重复值" + id);

				}else{
					Logger.verifyEquals(false, list.contains(id), "验证第" + i+ "条返回数据的id不存在重复值" + id);
					list.add(id);
				}
			
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_005() {
		Logger.start(true,"app好货商品接口- 验证返回结果中商品各字段信息完整性");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue,sort:apphaohuo1");
			searchproductinappBean.setFl("sproductid,source");
			searchproductinappBean.setLimit("0,100");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			JSONArray hitsAry = searchproductinappCall.getHits();
			

			for (int i = 1; i <= hitsAry.length(); i++) {
				
				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);
				
				Logger.verifyNotNull(json.getString("sproductid"), "检查第"+i+"条记录中的sproductid值是否为空");
				Logger.verifyNotNull(json.getString("sproduct"), "检查第"+i+"条记录中的sproduct值是否为空");
				Logger.verifyNotNull(json.getString("source"), "检查第"+i+"条记录中的source值是否为空");
				Logger.verifyNotNull(json.getString("ithirdcategoryid"), "检查第"+i+"条记录中的ithirdcategoryid值是否为空");
				Logger.verifyNotNull(json.getString("iuserid"),"检查第"+i+"条记录中的iuserid值是否为空");
			
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_006() {
		Logger.start(false,"app好货商品接口- 不传入关键字进行搜索，检查返回数据");
		try {
			//设置参数
			
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue,sort:apphaohuo1");
			searchproductinappBean.setFl("sproductid,source");
			searchproductinappBean.setLimit("0,10");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
		
			Logger.verifyEquals(true, searchproductinappCall.getHits().toString().equals("[]"), "返回商品信息为空");
			Logger.verifyEquals("INVALID_REQUEST", searchproductinappCall.getStatus(), "接口返回对应异常状态值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_007() {
		Logger.start(false,"app好货商品接口- 不传入info信息进行搜索，检查返回数据");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			//searchproductinappBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue,sort:apphaohuo1");
			searchproductinappBean.setFl("sproductid,source");
			searchproductinappBean.setLimit("0,10");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			Logger.verifyNotNull(searchproductinappCall.getHits().get(0), "检查接口应该有数据返回");
			Logger.verifyEquals("OK",searchproductinappCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(requestid,searchproductinappCall.getCommonInfo("requestid") , "检查接口请求id值");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("hostip"), "验证hostip不为空");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("algorithm"), "验证algorithm不为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_008() {
		Logger.start(false,"app好货商品接口- fl里传入一个不存在的返回值搜索，检查返回数据");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			//searchproductinappBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue,sort:apphaohuo1");
			searchproductinappBean.setFl("aaaa,sproductid,source");
			searchproductinappBean.setLimit("0,10");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			Logger.verifyNotNull(searchproductinappCall.getHits().get(0), "检查接口应该有数据返回");
			Logger.verifyEquals("OK",searchproductinappCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(requestid,searchproductinappCall.getCommonInfo("requestid") , "检查接口请求id值");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("hostip"), "验证hostip不为空");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("algorithm"), "验证algorithm不为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_009() {
		Logger.start(false,"app好货商品接口- 不传fl参数直接搜索，检查返回数据");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			
			searchproductinappBean.setLimit("0,10");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			Logger.verifyNotNull(searchproductinappCall.getHits().get(0), "检查接口应该有数据返回");
			Logger.verifyEquals("OK",searchproductinappCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(requestid,searchproductinappCall.getCommonInfo("requestid") , "检查接口请求id值");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("hostip"), "验证hostip不为空");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("algorithm"), "验证algorithm不为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_010() {
		Logger.start(false,"app好货商品接口- 搜索无匹配商品的关键字，检查返回数据");
		try {
			//设置参数
			String keyword = "对否是否未3发v";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			
			searchproductinappBean.setLimit("0,10");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			Logger.verifyEquals(true,searchproductinappCall.getHits().toString().equals("[]"), "接口无商品信息返回");
			Logger.verifyEquals("OK",searchproductinappCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(requestid,searchproductinappCall.getCommonInfo("requestid") , "检查接口请求id值");
			Logger.verifyEquals(false, searchproductinappCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("hostip"), "验证hostip不为空");
			Logger.verifyNotNull(searchproductinappCall.getCommonInfo("algorithm"), "验证algorithm不为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_011() {
		Logger.start(false,"app好货商品接口- 按类目对结果进行聚合，检查聚合结果");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			String stat = "term(ucategoryarray)";//按照类目聚类,结果包含1、2和3级类目
			
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setLimit("0,10");
			searchproductinappBean.setStat(stat);
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
		JSONObject statsArray =searchproductinappCall.getStats();
	//Logger.debug(statsArray.getJSONObject("ucategoryarray"));
		Logger.verifyEquals(true, statsArray.has("ucategoryarray"), "检查接口返回是否包含类目聚合结果");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_012() {
		Logger.start(false,"app好货商品接口- 按三级类目对结果进行聚合，检查聚合结果");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			String stat = "term(ithirdcategoryid)";//按照三级类目聚合
			
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setLimit("0,10");
			searchproductinappBean.setStat(stat);
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
		JSONObject statsArray =searchproductinappCall.getStats();
	
		Logger.verifyEquals(true, statsArray.has("ithirdcategoryid"), "检查接口返回是否包含三级类目聚合结果");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_013() {
		Logger.start(false,"app好货商品接口- 同时按类目和三级类目对结果进行聚合，检查聚合结果");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			String stat = "term(ucategoryarray),term(ithirdcategoryid)";//按照类目聚类,结果包含1、2和3级类目。和三级类目
			
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setLimit("0,10");
			searchproductinappBean.setStat(stat);
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
		JSONObject statsArray =searchproductinappCall.getStats();
	
		Logger.verifyEquals(true, statsArray.has("ithirdcategoryid"), "检查接口返回是否包含三级类目聚合结果");
		Logger.verifyEquals(true, statsArray.has("ucategoryarray"), "检查接口返回是否包含类目聚合结果");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_014() {
		Logger.start(false,"app好货商品接口- 检查聚合统计值的三级类目是否包含类目中");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			String stat = "term(ucategoryarray),term(ithirdcategoryid)";//按照类目聚类,结果包含1、2和3级类目。和三级类目
			
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setLimit("0,10");
			searchproductinappBean.setStat(stat);
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
		JSONObject statsArray =searchproductinappCall.getStats();
	
		//获取接口返回的ucategoryarray对象
		JSONObject uCategoryObject = statsArray.getJSONObject("ucategoryarray");
		//获取接口返回的ithirdcategoryid对象
		JSONObject ithirdCategoryObject = statsArray.getJSONObject("ithirdcategoryid");
		
		//获取uCategoryObject里的所有键名存入数组
		 String[] ucategoryarrayKey = searchproductinappCall.analyzeJsonToArray(uCategoryObject, "key");
		//获取ithirdCategoryObject里的所有键名存入数组
		 String[] ithirdCategoryKey = searchproductinappCall.analyzeJsonToArray(ithirdCategoryObject, "key");
		 
		 //判断ithirdCategoryObject 是否为uCategoryObject的子集
		
		 List listA = Arrays.asList(ucategoryarrayKey);
	     List listB = Arrays.asList(ithirdCategoryKey);
	   
	     Logger.verifyEquals(true,listA.containsAll(listB) , "验证三级类目集合是否包含在类目集合中");
	      
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_015() {
		Logger.start(false,"app好货商品接口- 搜索半价商品,检查接口返回结果是否支持半价");
		try {
			//设置参数
			String keyword = "测试";
			String requestid = "53453gge4er3freg";
			String stat = "term(ucategoryarray),term(ithirdcategoryid)";//按照类目聚类,结果包含1、2和3级类目。和三级类目
			int ifHalfPrice = 1;//1表示支持半价，0，表示不支持半价
			
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+keyword+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setLimit("0,10");
			searchproductinappBean.setStat(stat);
			searchproductinappBean.setFl("ifHalfPrice,sproductid,dsr,rankscore,source");
			searchproductinappBean.setFilter("term(ifHalfPrice,"+ifHalfPrice+")");
			
				
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
		JSONObject statsArray =searchproductinappCall.getStats();
		//先确定到底是c端还是m端商品，然后去对应的数据库里检查该商品是否为半价商品
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ProductKeyword_016() {
		Logger.start(true,"app好货商品接口- 搜索关键字为买手名，校验返回数据是否为该买手商品");
		try {
			//设置参数
			String shopName = "JPseller";
			String requestid = "53453gge4er3freg";
			searchproductinappBean.setModule("haohuosearch");
			searchproductinappBean.setAppkey(3);
			searchproductinappBean.setQuery("keyword(mixkeyword,"+shopName+")");
			searchproductinappBean.setPlatform("pc");
			searchproductinappBean.setRequestid(requestid);
			searchproductinappBean.setExplain("Flase");
			searchproductinappBean.setInfo("userid:111,cookieid:111555555555,idfa:idfavalue,imei:imeivalue,sort:apphaohuo1");
			searchproductinappBean.setFl("sproductid,source,mixkeyword,shopName");
			searchproductinappBean.setLimit("0,10");
			
			searchproductinappCall.setData(searchproductinappBean);
			searchproductinappCall.callService();	
			
			JSONArray hits = searchproductinappCall.getHits();

			// 获取接口返回数据中的所有sproduct值
			for (int i = 1; i <= hits.length(); i++) {
				String hitsOne = hits.getString(i - 1);
				JSONObject hitsOnes = new JSONObject(hitsOne);
				String name = (String) hitsOnes.get("shopName");
				Logger.verifyEquals(shopName, name, "返回商品都为"+shopName+"所属商品");
				

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	//
	//TODO 补验证ithirdCategoryKey的值是否有效的case
	/*
	 * 1.取出类目id，通过类目id查是否含有有效商品
	 * */
}